package com.leetcode.LC;

import java.util.Arrays;

public class LC1646 {
    public int getMaximumGenerated(int n) {
        if (n == 0) {
            return 0;
        }
        if (n == 1) {
            return 1;
        }
        int[] nums = new int[n + 1];
        nums[0] = 0;
        nums[1] = 1;
        for (int i = 1; i < n + 1; i++) {
            if (2 <= 2 * i && 2 * i <= n) {
                nums[2 * i] = nums[i];
            }
            if (2 <= 2 * i + 1 && 2 * i + 1 <= n) {
                nums[2 * i + 1] = nums[i] + nums[i + 1];
            }
        }

        Arrays.sort(nums);
        return nums[n];
    }

    public static void main(String[] args) {
        System.out.println(new LC1646().getMaximumGenerated(7));
    }
}
